package password

import (
	"golang.org/x/crypto/bcrypt"
)

// HashAndSalt 加密密码
func HashAndSalt(password string) string {
	bytePassword := []byte(password)
    hashPassword, _ := bcrypt.GenerateFromPassword(bytePassword, bcrypt.MinCost)
    return string(hashPassword)
}

// ValidatePasswords 验证密码
func ValidatePasswords(hashedPassword string, plainPassword string) bool {
    byteHashPassword := []byte(hashedPassword)
	bytePlainPassword := []byte(plainPassword)
    err := bcrypt.CompareHashAndPassword(byteHashPassword, bytePlainPassword)
    return err == nil
}